// pages/personal/personal.js
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        defaultAvatar: "http://img.zhxcxmall.com/static/default-avatar3.png",
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    onShow: function () {
        app.toPromise(wx.getStorage, { key: "user" }).then(res => {
            return { userInfo: res.data }
        }).catch(err => {
            return app.toPromise(wx.getUserInfo)
        }).then(res => {
            if (res.userInfo) {
                this.setData({
                    user: res.userInfo
                })
                app.http.post("member/save-info", {
                    data: res.userInfo
                })
                wx.setStorage({
                    key: 'user',
                    data: res.userInfo,
                })
            }
        }).catch(err => {

        })
    },
    getUser(evt) {
        const user = evt.detail.userInfo
        if (user) {
            wx.setStorage({
                key: 'user',
                data: user,
            })
            this.setData({
                user
            })
            app.http.post("member/save-info", {
                data: user
            })
        }
    },
})